var Qiniu_UploadUrl = "http://up-z2.qiniup.com";
var upto_Qiniu = function(obj,index,uuid) {
		var f=obj.file;
		var token=obj.token;
		var key=obj.key;
		var progress=obj.progress;
		var success=obj.success;
		var error=obj.error;
		//var p = Promise.resolve(index);
		return function(index){
			return new Promise(function(resolve,reject){
			var xhr = new XMLHttpRequest();
			xhr.open('POST', Qiniu_UploadUrl, true);
			var formData;
			formData = new FormData();
			if (key !== null && key !== undefined) 
			formData.append('key', key); 
			formData.append('token', token);
			formData.append('file', f);
			formData.append('reImgFlag',uuid);
			/*if(progress && typeof progress ==='function'){
				xhr.upload.addEventListener("progress", function(evt){
					progress.call(this,evt)
				}, false);
			}*/
			xhr.onreadystatechange = function(response) {
				if (xhr.readyState == 4 && xhr.status == 200 && xhr.responseText != "") {
					var blkRet = JSON.parse(xhr.responseText);
					console && console.log(blkRet);
					//if(blkRet==null){
					resolve(blkRet,uuid)
					//success.call(null,blkRet,reImgFlag);
					//}
				}else if (xhr.status != 200 && xhr.responseText != "") {
					//error.call(null,xhr.responseText);
					reject(xhr.responseText);
				}
			};
			//startDate = new Date().getTime();
			xhr.send(formData);	
		})

	}
		//return p
	/*xhr.upload.addEventListener("progress", function(evt) {
		if (evt.lengthComputable) {
			var nowDate = new Date().getTime();
			taking = nowDate - startDate;
			var x = (evt.loaded) / 1024;
			var y = taking / 1000;
			var uploadSpeed = (x / y);
			var formatSpeed;
			if (uploadSpeed > 1024) {
				formatSpeed = (uploadSpeed / 1024).toFixed(2) + "Mb\/s";
			} else {
				formatSpeed = uploadSpeed.toFixed(2) + "Kb\/s";
			}
			var percentComplete = Math.round(evt.loaded * 100 / evt.total);
			progressbar.progressbar("value", percentComplete);
				                    // console && console.log(percentComplete, ",", formatSpeed);
			}
		}, false);*/


}
export default upto_Qiniu